/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

#include <gen/keywordsMap.h>
#include <lexer/keywordsUtil.h>
#include <lexer/token/letters.h>
#include <macros.h>
#include <utils/span.h>

namespace panda::es2panda::lexer {

class Keywords {
public:
    explicit Keywords(Lexer* lexer, lexer::LexerNextTokenFlags flags) : util_(KeywordsUtil(lexer, flags)) {}
    NO_COPY_SEMANTIC(Keywords);
    NO_MOVE_SEMANTIC(Keywords);
    ~Keywords() = default;

    KeywordsUtil &Util() {
        return util_;
    }

    // NOLINTNEXTLINE(readability-function-size)
    static void SetKeyword(KeywordsUtil *util, const KeywordString& kws) {
        switch(kws.keywordType) {
% keywords.each do |group|
%   group.each do |key, kw|
        case <%= kw[1] %>: {
            return util->SetKeyword<<%= kw[1] %>>(kws.str, kws.tokenType);
        }
%   end
% end
        default: {
            break;
        }
        }
    }

% functions.each do |key, prefixes|
    inline void Scan<%= key.upcase %>()
    {
        switch(util_.Iterator().Peek()) {
% prefixes.select{|p| !p.nil? }.each do |prefix|
        case LEX_CHAR_LOWERCASE_<%=prefix.upcase%>: /* '<%=prefix%>' */ {
            util_.Iterator().Forward(1);
            Scan<%= key.upcase %><%= prefix.upcase %>();
            return;
        }
% end
% if prefixes.include?(nil)
% kw = keywords.find{ |x| x.has_key?(key)}[key]
        default: {
            if (!KeywordsUtil::IsIdentifierPart(util_.Iterator().PeekCp())) {
                util_.SetKeyword<<%=kw[1]%>>("<%=key%>", <%=kw[0]%>);
                return;
            }
            break;
        }
        }
% else
        default: {
            break;
        }
        }
% end
        util_.ScanIdContinueMaybeKeyword(Span<const KeywordString>(KeywordsMap::KEYWORDS_<%= key[0].upcase %>));
    }

% end

private:
    KeywordsUtil util_;
};

} // namespace panda::es2panda::lexer
